//
//  MapViewC.m
//  UniverseProject
//
//  Created by king on 2021/6/22.
//  Copyright © 2021 Cloud2209. All rights reserved.
//

#import <MAMapKit/MAMapKit.h>
#import <AMapFoundationKit/AMapFoundationKit.h>
#import "MapViewC.h"

@interface MapViewC ()<MAMapViewDelegate>

@property (nonatomic, weak)MAMapView *mapView;

@end

@implementation MapViewC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    ///地图需要v4.5.0及以上版本才必须要打开此选项（v4.5.0以下版本，需要手动配置info.plist）
    [AMapServices sharedServices].enableHTTPS = YES;
    
    ///初始化地图
    MAMapView *_mapView = [[MAMapView alloc] initWithFrame:self.view.bounds];
    
    ///把地图添加至view
    [self.view addSubview:_mapView];
    self.mapView = _mapView;
    
    ///如果您需要进入地图就显示定位小蓝点，则需要下面两行代码
    _mapView.showsUserLocation = YES;
    _mapView.userTrackingMode = MAUserTrackingModeNone;
    _mapView.delegate = self;
    [_mapView setZoomLevel:16.3];
    
    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(30.526485, 115.356386);
    [self.mapView setCenterCoordinate:coordinate animated:YES];
}



- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
//    114.356386,30.526485
    MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];
    pointAnnotation.coordinate = CLLocationCoordinate2DMake(30.526485, 114.356386);
    pointAnnotation.title = @"银泰创意城";
    pointAnnotation.subtitle = @"7楼北科天翼";
    [_mapView addAnnotation:pointAnnotation];
    
//
}


- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id <MAAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MAPointAnnotation class]])
    {
        static NSString *pointReuseIndentifier = @"pointReuseIndentifier";
        MAPinAnnotationView*annotationView = (MAPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndentifier];
        if (annotationView == nil)
        {
            annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndentifier];
        }
        annotationView.canShowCallout= YES;       //设置气泡可以弹出，默认为NO
        annotationView.animatesDrop = YES;        //设置标注动画显示，默认为NO
        annotationView.draggable = YES;        //设置标注可以拖动，默认为NO
        annotationView.pinColor = MAPinAnnotationColorPurple;
        return annotationView;
    }
    return nil;
}


@end
